<?php

namespace App\Console\Commands;

use App\Models\ProxyUser;
use App\Models\User;
use App\Services\ProxyService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class GetProxyUserStatus extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:getProxyUserStatus';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '查询代理帐号状态';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(ProxyService $proxyService)
    {
        $data = ProxyUser::get();
        foreach ($data as $item) {
            $user_id = $item->user_id;
            $result = $proxyService->proxyUserList($user_id);
            if (empty($result)) {
                continue;
            }
            foreach ($result as $value) {
                if ($item->username == $value['username']) {
                    ProxyUser::where('user_id', $user_id)->update(['status' => $value['status']]);
                }
            }
        }
    }
}
